﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AltimilliaLibrary.Intelligence
{
    public class SpriteScript
    {
        public List<SpriteAction> Actions { get; set; }
        private int currentAction;
        private int totalFrames;

        public SpriteScript(List<SpriteAction> Actions)
        {
            this.Actions = Actions;
            totalFrames = Actions.Count;
            currentAction = 0;
        }

        public void Execute(Sprite gc)
        {
            if (!CurrentAction.IsStarted)
            {
                CurrentAction.StartUp(gc);
                CurrentAction.ActionFinished += new SpriteAction.SpriteActionFinished(SpriteActionFinished);
            }
            if (!CurrentAction.finished)
            {
                CurrentAction.RunAction(gc);
            }
        }

        public SpriteAction CurrentAction
        {
            get
            {
                return Actions[currentAction];
            }
        }

        public void SpriteActionFinished(SpriteAction act)
        {
          act.ActionFinished -= SpriteActionFinished;
            currentAction++;
            currentAction %= totalFrames;
            Debug.WriteLine("Current Action Is : " + currentAction);

        }
    }
}
